package sort;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * Created by liuwei on 2017/11/16.
 */
public class SortTest {

    public static void main(String[] args) {

        User u1 = new User("001",-1);
        User u2 = new User("002",5);
        User u3 = new User("003",4);
        User u4 = new User("004",-1);
        List<User> userList = new ArrayList<User>();
        userList.add(u1);
        userList.add(u2);
        userList.add(u3);
        userList.add(u4);
        Collections.sort(userList, new Comparator<User>() {
            public int compare(User o1, User o2) {
                if(o1.getNumber() == -1){
                    return 1;
                }else if(o2.getNumber() == -1){
                    return -1;
                }
                return o1.getNumber() - o2.getNumber();
            }
        });
        for (User u:userList){
            System.out.println(u);
        }




    }
}
